//
//  LocationButton.m
//  DianYing5
//
//  Created by 夏晓霖 on 15/7/20.
//  Copyright (c) 2015年 uskr. All rights reserved.
//

#import "LocationButton.h"

@implementation LocationButton

-(id)initWithFrame:(CGRect)frame withTitle:(NSString *)title withBackgroundColor:(UIColor*)color withAction:(void(^)(LocationButton *button))action;

{
    if(self = [super initWithFrame:frame])
    {
        self.action = action;
        [self setTitle:title forState:UIControlStateNormal];
        if(color)
            self.backgroundColor = color;
        else
            self.backgroundColor = [UIColor blueColor];
        self.layer.cornerRadius = 6;
        self.clipsToBounds = YES;
        
        [self addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(void)btnClick:(LocationButton *)button
{
    //作用: 原来被点击执行target-action对应的方法
    //现在: 判断action是否已经设置block, 如果被设置, 执行block
    if(self.action)
    {
        self.action(button);
    }
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
